//
//  DetailHeaderView.m
//  MyTrip
//
//  Created by zhang on 15/8/25.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "DetailHeaderView.h"
#import "DiaryDetailHeader.h"
#import "UIImageView+WebCache.h"

@interface DetailHeaderView ()

@property(nonatomic,retain)UIVisualEffectView *visual;

@end

@implementation DetailHeaderView

- (void)dealloc
{
    [_mileageNameLabel release];
    [_recommendationsLabel release];
    [_recommendationsNameLabel release];
    [_mileageLabel release];
    [_daysLabel release];
    [_startDayLabel release];
    [_titleLabel release];
    [_authorLabel release];
    [_authorView release];
    [_headerBackView release];
    [super dealloc];
}

- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.visual = [[[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease];
        self.visual.frame = CGRectMake(0, 0, frame.size.width, frame.size.height / 2);
        self.headerBackView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height / 2)] autorelease];
        [_headerBackView addSubview:_visual];
        [self addSubview:_headerBackView];
        
        
        self.authorView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60 * OffWidth, 60 * OffWidth)] autorelease];
        _authorView.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
        _authorView.layer.borderWidth = 2 * OffWidth;
        _authorView.layer.borderColor = [UIColor whiteColor].CGColor;
        _authorView.layer.masksToBounds = YES;
        _authorView.layer.cornerRadius = 30 * OffWidth;
        [self addSubview:_authorView];
        
        self.authorLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200 * OffWidth, 30 * OffHeight)] autorelease];
        _authorLabel.center = CGPointMake(_authorView.center.x, _authorView.center.y + 35 * OffHeight + 3 * OffHeight);
        [self addSubview:_authorLabel];
        
        self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200 * OffWidth, 30 * OffHeight)] autorelease];
        _titleLabel.center = CGPointMake(_authorView.center.x, _authorView.center.y + 35 * OffHeight + 25 * OffHeight);
        [self addSubview:_titleLabel];
        
        self.mileageNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        _mileageNameLabel.center = CGPointMake(_authorView.center.x, _authorView.center.y + (35 + 25 + 25 + 40) * OffHeight);
        [self addSubview:_mileageNameLabel];
        
        self.mileageLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        _mileageLabel.center = CGPointMake(_mileageNameLabel.center.x, _mileageNameLabel.center.y + 20 * OffHeight);
        [self addSubview:_mileageLabel];
        
        
        self.startDayLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_mileageNameLabel.frame.origin.x - _mileageNameLabel.frame.size.width, _mileageNameLabel.frame.origin.y, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        [self addSubview:_startDayLabel];
        
        self.daysLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_startDayLabel.frame.origin.x, _startDayLabel.frame.origin.y + _startDayLabel.frame.size.height, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        [self addSubview:_daysLabel];
        
        self.recommendationsNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_mileageNameLabel.frame.size.width + _mileageNameLabel.frame.origin.x, _mileageNameLabel.frame.origin.y, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        [self addSubview:_recommendationsNameLabel];
        
        
        self.recommendationsLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_recommendationsNameLabel.frame.origin.x, _mileageLabel.frame.origin.y, frame.size.width / 3 - 10 * OffWidth, 20 * OffHeight)] autorelease];
        [self addSubview:_recommendationsLabel];
        
    }
    return self;
}

- (void)setValueWithModel:(DiaryDetailHeader *)model{
    [_headerBackView sd_setImageWithURL:[NSURL URLWithString:model.headerImage] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    [_authorView sd_setImageWithURL:[NSURL URLWithString:model.authorImage] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    [_authorLabel setText:[NSString stringWithFormat:@"by %@", model.authorName]];
    _authorLabel.textAlignment = NSTextAlignmentCenter;
    _authorLabel.font = [UIFont systemFontOfSize:10];
    _authorLabel.alpha = 0.5;
    
    [_titleLabel setText:model.title];
    [_titleLabel setTextAlignment:NSTextAlignmentCenter];
    [_titleLabel setFont:[UIFont systemFontOfSize:18]];
    _titleLabel.shadowOffset = CGSizeMake(1 * OffWidth, 1 * OffHeight);
    _titleLabel.shadowColor = [UIColor grayColor];
    
    
    [_startDayLabel setText:model.startTime];
    _startDayLabel.textAlignment = NSTextAlignmentCenter;
    _startDayLabel.font = [UIFont systemFontOfSize:11];
    
    [_daysLabel setText:[NSString stringWithFormat:@"%ld", (long)model.days]];
    _daysLabel.textAlignment = NSTextAlignmentCenter;
    _daysLabel.font = [UIFont systemFontOfSize:11];
    _daysLabel.alpha = 0.5;
    
    [_mileageNameLabel setText:@"里程"];
    _mileageNameLabel.textAlignment = NSTextAlignmentCenter;
    _mileageNameLabel.font = [UIFont systemFontOfSize:11];
    
    [_mileageLabel setText:[NSString stringWithFormat:@"%ld", (long)model.mileage]];
    _mileageLabel.textAlignment = NSTextAlignmentCenter;
    _mileageLabel.font = [UIFont systemFontOfSize:11];
    _mileageLabel.alpha = 0.5;
    
    [_recommendationsNameLabel setText:@"喜欢"];
    _recommendationsNameLabel.textAlignment = NSTextAlignmentCenter;
    _recommendationsNameLabel.font = [UIFont systemFontOfSize:11];
    
    [_recommendationsLabel setText:[NSString stringWithFormat:@"%ld", (long)model.like]];
    _recommendationsLabel.textAlignment = NSTextAlignmentCenter;
    _recommendationsLabel.font = [UIFont systemFontOfSize:11];
    _recommendationsLabel.alpha = 0.5;
    
}








@end
